package com.nabi.library.contents.elements.figure
{
	import com.nabi.library.contents.elements.NabiObject;
	import com.nabi.library.contents.elements.Outline;
	import com.nabi.library.contents.elements.segment.LineSegment;
	import com.nabi.library.contents.elements.segment.MoveSegment;
	import com.nabi.library.contents.geom.ITransform;
	import com.nabi.library.contents.geom.NativeTransform;
	
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	public class Line extends NabiObject
	{
		public function Line($p1x:Number = 0, $p1y:Number = 0, $p2x:Number = 0, $p2y:Number = 0)
		{
			var outline:Outline = new Outline();
			var outlineList:Vector.<Outline> = new Vector.<Outline>();
			
			outline.AddTail(new MoveSegment(Vector.<Number>([$p1x, $p1y])));
			outline.AddTail(new LineSegment(Vector.<Number>([$p2x, $p2y])));
			outline.Update();
			outlineList.push(outline);
			
			super(outlineList);
			
			var transform:ITransform = new NativeTransform(this);
			SetTransform(transform);
		}
		
		private function revisionRect($rect:Rectangle): void
		{
			if($rect.width < 1) {
				$rect.width = 10;
				$rect.x += -5;
			}
			
			if($rect.height < 1) {
				$rect.height = 10;
				$rect.y += -5;
			}
		}
		
		override public function getBounds($targetCoordinateSpace:DisplayObject): Rectangle
		{
			var result:Rectangle = super.getBounds($targetCoordinateSpace);
			revisionRect(result);
			
			return result;
		}		
		
		override public function getRect($targetCoordinateSpace:DisplayObject): Rectangle
		{
			var result:Rectangle = super.getRect($targetCoordinateSpace);
			revisionRect(result);
			
			return result;
		}
	}
}